/*
 * This file is part of Jeve.

    Jeve is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.

    Jeve is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
    Copyright 2007 Jochen Bedersdorfer (beders@yahoo.com)
 *
 */
package de.monoid.eve;

import java.io.UnsupportedEncodingException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * Wrapper for the APIKey.
 * @author beders
 */
public class APIKey {
  private String key;

  /**
   * Create an APIKey object.
   * @param aKey the api key
   * 
   */
  public APIKey(String aKey) {
    key = aKey;
  }

  public boolean equals(Object obj) {
    if (obj == null) {
      return false;
    }
    if (getClass() != obj.getClass()) {
      return false;
    }
    final APIKey other = (APIKey) obj;
    if (this.key != other.key && (this.key == null || !this.key.equals(other.key))) {
      return false;
    }
    return true;
  }

  public int hashCode() {
    int hash = 3;
    hash = 97 * hash + this.key != null ? this.key.hashCode() : 0;
    return hash;
  }

  /**
   * Encode the apikey as part of an URL query
   * @param requestData the buffer for the URL query
   */
  void encode(StringBuilder requestData) {
    try {
      requestData.append("apikey").append('=').append(java.net.URLEncoder.encode(key, "UTF-8"));
    } catch (UnsupportedEncodingException ex) {
      Logger.getLogger("global").log(Level.SEVERE, null, ex);
    }
  }

}
